-module(test).
-compile(export_all).

% initial implementation
nt_extract_neighbors([]) -> [];
nt_extract_neighbors([H|T]) -> 
	case H of 
		{integer, _, X} -> [X | nt_extract_neighbors(T)];
		H -> error
	end.


% a tail-recursive implemenation:
extract_neighbors(Token) ->
	extract_neighbors_helper(Token, []). 

extract_neighbors_helper([], Res) -> Res;
extract_neighbors_helper([H|T], Res) -> 
	case H of 
		{integer, _, X} -> 
			extract_neighbors_helper(T, lists:append(Res, [X]));
		H -> error
	end. 
